/** 支持入参，返回函数 */
export type ActionFnByParams<T> = (options?: T) => (value: any) => { checkHandle: boolean, value: any }
/** 不支持入参，返回配置 */
export type ActionFn = (value: any) => { checkHandle: boolean, value: any }

export default class InterceptorActionHandler {
  private actions: ActionFn[] = []

  add = (action: ActionFn) => {
    this.actions.push(action)
    return this
  }

  handleByAllAction = (value: any) => {
    let newValue = value
    this.actions.forEach(action => {
      const res = action(newValue)
      if (res.checkHandle) {
        const val = res.value()
        if (val) newValue = val
      }
    })
    return newValue
  }
}
